<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: inc.get_top_level_domain.php 530 2015-02-28 11:41:34Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 530 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2015-02-28 11:41:34 +0000 (Sat, 28 Feb 2015) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

function get_top_level_domain($url) {
	if(strpos($url, '://')) {
		$url = parse_url($url);
		$url = $url['host'];
	}
	$domain_array = explode('.', $url);
	$domain_size = sizeof($domain_array);
	if($domain_size > 1) {
		if(is_numeric($domain_array[$domain_size -2]) && is_numeric($domain_array[$domain_size -1]))
			return false;
		else {
			$domain_path = '';
			for ($domain_part = $domain_size-2; $domain_part < $domain_size; $domain_part++) {
				$domain_path .= $domain_array[$domain_part];
				if($domain_part != ($domain_size -1))
					$domain_path .= '.';
			}
			return $domain_path;
		}
	} else
		return false;
}